package com.pwc.conversionTool.soapUtil.thread;

import java.util.Arrays;
import java.util.List;

import com.googlecode.objectify.Key;
import com.pwc.GAE.blobstore.BlobstoreManager;
import com.pwc.conversionTool.biz.ProjectBiz;
import com.pwc.conversionTool.biz.TaskBiz;
import com.pwc.conversionTool.dao.LogDao;
import com.pwc.conversionTool.entity.Account;
import com.pwc.conversionTool.entity.DataType;
import com.pwc.conversionTool.entity.TaskFlowLog;
import com.pwc.conversionTool.entity.Operation;
import com.pwc.conversionTool.entity.Project;
import com.pwc.conversionTool.entity.Task;
import com.pwc.conversionTool.entity.TaskFlow;

public class TaskProcess {
	
	private  TaskFlow taskFlow;
	
	private  Account account;
	
	private List<Task> tasks;
	
	private TaskFlowLog log;
	
	private TaskBiz taskBiz=new TaskBiz();
	private ProjectBiz projectBiz=new ProjectBiz();
	private LogDao logDao=new LogDao();
	
	public  void initial(TaskFlow taskFlow,Account account,TaskFlowLog log){
		this.taskFlow=taskFlow;
		this.account=account;
		this.tasks=taskBiz.getTasksByTaskFlowId(taskFlow.getId());
		this.log=log;
		
	}
	
	
	
	public void runWorkFlow()
	{
		try {
			
			for (Task task : tasks) {
				task(task);
			}
			
		} catch (Exception e) {
			log.addMessage("error in run workflow");
			log.addMessage(e.getMessage());
			log.addMessage(Arrays.toString(e.getStackTrace()));
			
			e.printStackTrace();
			
			
		}finally
		{
			logDao.saveLog(log);
		}
	}
	
	
	
	
	public void task(Task task)
	{
		Key<Operation> operationkey= task.getOperation();
		
		Operation operation=projectBiz.getOperationByKey(operationkey);
		
		
		
		List<String> keys=task.getFiles();
		
		
		
		if(operation.getDataAdaptorData().getDataType().equalsIgnoreCase(DataType.CSV.toString()))
		{
			csvOperation(keys, operation);
		}
		
	}
	
	
	public void csvOperation(List<String> keys,Operation operation)
	{
		for (String key : keys) {
		//	BlobstoreManager blobstoreManager=new BlobstoreManager(req)
		}
	}
	
	
	
	
	
	
	
	
	
	
	
	
	

}
